﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using IFactory;

public partial class Report_ViewHandShake : System.Web.UI.Page
{
    UserInfoManager dllUserInfo = new UserInfoManager();
    Model.UserInfo objUserInfo = new Model.UserInfo();
    public string _realName = "";
    MonthHandShakeManager dllMonthHandShakeManager = new MonthHandShakeManager();
    WeekHandShakeManager dllWeekHandShakeManager = new WeekHandShakeManager();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bindGridView();
        }
    }


    /// <summary>
    /// 绑定GridView
    /// </summary>
    void bindGridView()
    {
        int _Type = Utility.HttpHelp.getParamsInt("Type");
        if (_Type == 1)
        {
            object[] _user = new object[1];
            _user[0] = objUserInfo.UserName;
            DataTable _usertable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _user);
            if (_usertable.Rows.Count > 0)
            {
                _realName = _usertable.Rows[0]["RealName"].ToString();
            }
            object[] _value = new object[2];
            _value[0] = Utility.HttpHelp.getParamsInt("MonthDate");
            _value[1] = Utility.HttpHelp.getParamsInt("PlanSendState");
            DataTable _monthHandShake = dllMonthHandShakeManager.getMonthHandkShakeByMonthDateAndIsConsensus( _value);
            this.gdvHandShake.DataSource = _monthHandShake;
            this.gdvHandShake.DataBind();
            for (int i = 0; i < this.gdvHandShake.Rows.Count; i++)
            {
                if (_monthHandShake.Rows[i]["IsConsensus"].ToString() == "4")
                {
                    this.gdvHandShake.Rows[i].Cells[5].Text = "达成共识";

                }
                else
                {
                    this.gdvHandShake.Rows[i].Cells[5].Text = "否";

                }


                string _Lengthstart = this.gdvHandShake.Rows[i].Cells[3].Text;

                if (_Lengthstart.Length > 9)
                {
                    _Lengthstart = _Lengthstart.Substring(0, 9);//截取字符串，从左边截取10个字符串
                    this.gdvHandShake.Rows[i].Cells[3].Text = _Lengthstart;
                }

            }
            if (this.gdvHandShake.Rows.Count == 0)
            {
                this.gdvHandShake.DataSource = createTable();
                this.gdvHandShake.DataBind();
            }
        }
        //周握手关系
        else
        {
            object[] _user = new object[1];
            _user[0] = objUserInfo.UserName;
            DataTable _usertable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _user);
            if (_usertable.Rows.Count > 0)
            {
                _realName = _usertable.Rows[0]["RealName"].ToString();
            }
            object[] _value = new object[2];
            _value[0] = Utility.HttpHelp.getParamsInt("WeekDate");
            _value[1] = Utility.HttpHelp.getParamsInt("PlanSendState");
            DataTable _weekHandShake = dllWeekHandShakeManager.getWeekHandkShakeByWeekDateAndIsConsensus(_value);
            this.gdvHandShake.DataSource = _weekHandShake;
            this.gdvHandShake.DataBind();
            for (int i = 0; i < this.gdvHandShake.Rows.Count; i++)
            {
                if (_weekHandShake.Rows[i]["IsConsensus"].ToString() == "4")
                {
                    this.gdvHandShake.Rows[i].Cells[5].Text = "达成共识";

                }
                else
                {
                    this.gdvHandShake.Rows[i].Cells[5].Text = "否";
                }


                string _Lengthstart = this.gdvHandShake.Rows[i].Cells[3].Text;

                if (_Lengthstart.Length > 9)
                {
                    _Lengthstart = _Lengthstart.Substring(0, 9);//截取字符串，从左边截取10个字符串
                    this.gdvHandShake.Rows[i].Cells[3].Text = _Lengthstart;
                }

            }
            if (this.gdvHandShake.Rows.Count == 0)
            {
                this.gdvHandShake.DataSource = createTable();
                this.gdvHandShake.DataBind();
            }
        }
    }


    /// <summary>
    /// 生成空白行
    /// </summary>
    /// <returns></returns>
    DataTable createTable()
    {
        DataTable _dt = new DataTable();
        DataColumn dc = new DataColumn("HandShakeId");
        _dt.Columns.Add(dc);
        dc = new DataColumn("CreateDate");
        _dt.Columns.Add(dc);
        dc = new DataColumn("MonthDate");
        _dt.Columns.Add(dc);
        dc = new DataColumn("Sponsor");
        _dt.Columns.Add(dc);
        dc = new DataColumn("Participant");
        _dt.Columns.Add(dc);
        dc = new DataColumn("CompleteTime");
        _dt.Columns.Add(dc);
        dc = new DataColumn("HandShakeContents");
        _dt.Columns.Add(dc);
        dc = new DataColumn("IsConsensus");
        _dt.Columns.Add(dc);
        dc = new DataColumn("CheckNote");
        _dt.Columns.Add(dc);
        dc = new DataColumn("IsDelete");
        _dt.Columns.Add(dc);
        DataRow dr = _dt.NewRow();
        dr["HandShakeId"] = "";
        dr["CreateDate"] = "";
        dr["MonthDate"] = "";
        dr["Sponsor"] = "";
        dr["Participant"] = "";
        dr["CompleteTime"] = "";
        dr["HandShakeContents"] = "";
        dr["IsConsensus"] = "";
        dr["CheckNote"] = "0";
        dr["IsDelete"] = "";
        _dt.Rows.Add(dr);
        return _dt;
    }

    /// <summary>
    /// 自动排序
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gdvHandShake_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1)
        {
            int id = e.Row.RowIndex + 1;
            e.Row.Cells[0].Text = id.ToString();
        }
    }
}
